home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume21 / squeeze1.711 < prev    next >
Encoding:
Internet Message Format  |  1990-02-05  |  44.4 KB

  1. Subject:  v21i001:  A file compression program
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Dan Bernstein <brnstnd@stealth.acf.nyu.edu>
  7. Posting-number: Volume 21, Issue 1
  8. Archive-name: squeeze1.711
  9.  
  10. squeeze, unsqueeze -- compress data with Miller-Wegman encoding.
  11.  
  12. Edit the options in Makefile and type make. squeeze and unsqueeze will be
  13. the executable programs; the nroff'ed man files will go into squeeze.1,
  14. unsqueeze.1, etc. squeeze and unsqueeze are filters only; sqz, sqzdir,
  15. unsqz, unsqzdir, and mwcat apply them to files.  Note that the shell
  16. scripts need filterfile version 1.2 or later.
  17.  
  18. I don't pretend to know your machine's setup so there's no make install.
  19.  
  20. Read CHANGES for a list of changes. Type squeeze -C and squeeze -W for
  21. copyright and warranty information, squeeze -H for help; similarly for
  22. unsqueeze.
  23.  
  24. #! /bin/sh
  25. # This is a shell archive.  Remove anything before this line, then unpack
  26. # it by saving it into a file and typing "sh file".  To overwrite existing
  27. # files, type "sh file -c".  You can also feed this as standard input via
  28. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  29. # will see the following message at the end:
  30. #        "End of shell archive."
  31. # Contents:  README CHANGES mwcat.man squeeze.man sqz.man sqzdir.man
  32. #   unsqueeze.man squeeze.c unsqueeze.c sqz sqzdir unsqz unsqzdir
  33. #   mwcat Makefile
  34. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  35. if test -f 'README' -a "${1}" != "-c" ; then 
  36.   echo shar: Will not clobber existing file \"'README'\"
  37. else
  38. echo shar: Extracting \"'README'\" \(1543 characters\)
  39. sed "s/^X//" >'README' <<'END_OF_FILE'
  40. Xsqueeze, unsqueeze - compress data with Miller-Wegman encoding
  41. X
  42. Xsqueeze version 1.711, October 28, 1989.
  43. XCopyright (c) 1989, Daniel J. Bernstein.
  44. XAll rights reserved.
  45. X
  46. XThis distribution packaged October 28, 1989.
  47. X
  48. XFiles:
  49. XCHANGES         Description of changes since first distributed version
  50. XREADME          This document
  51. XMakefile        Installation commands
  52. Xsqueeze.c       The squeeze program
  53. Xunsqueeze.c     The unsqueeze program
  54. Xsqz             A shell script to apply squeeze to files
  55. Xsqzdir          A shell script to apply squeeze to a directory hierarchy
  56. Xunsqz           A shell script to apply unsqueeze to files
  57. Xunsqzdir        A shell script to apply unsqueeze to a directory unhierary
  58. Xmwcat           A shell script to apply cat to squeezed files
  59. Xsqueeze.man     Documentation for squeeze
  60. Xunsqueeze.man   Documentation for unsqueeze
  61. Xsqz.man         Documentation for sqz, unsqz
  62. Xsqzdir.man      Documentation for sqzdir, unsqzdir
  63. Xmwcat.man       Documentation for mwcat
  64. X
  65. XEdit the options in Makefile and type make. squeeze and unsqueeze
  66. Xwill be the executable programs; the nroff'ed man files will go into
  67. Xsqueeze.1, unsqueeze.1, etc. squeeze and unsqueeze are filters only; 
  68. Xsqz, sqzdir, unsqz, unsqzdir, and mwcat apply them to files.
  69. XNote that the shell scripts need filterfile version 1.2 or later.
  70. X
  71. XI don't pretend to know your machine's setup so there's no make install.
  72. X
  73. XRead CHANGES for a list of changes. Type squeeze -C and squeeze -W
  74. Xfor copyright and warranty information, squeeze -H for help; similarly
  75. Xfor unsqueeze.
  76. END_OF_FILE
  77. if test 1543 -ne `wc -c <'README'`; then
  78.     echo shar: \"'README'\" unpacked with wrong size!
  79. fi
  80. # end of 'README'
  81. fi
  82. if test -f 'CHANGES' -a "${1}" != "-c" ; then 
  83.   echo shar: Will not clobber existing file \"'CHANGES'\"
  84. else
  85. echo shar: Extracting \"'CHANGES'\" \(261 characters\)
  86. sed "s/^X//" >'CHANGES' <<'END_OF_FILE'
  87. XVersion 1.711, 10/28/89. (Can't wait for 1.7111, 1.71111111, ... :-) )
  88. X
  89. XPut in new copyright notice and warranty.
  90. X
  91. XVersion 1.71, 9/27/89.
  92. X
  93. Xsqueeze and unsqueeze now complain about being given a filename.
  94. XAdded sqz, sqzdir, unsqz, unsqzdir, mwcat.
  95. X
  96. XVersion 1.7.
  97. END_OF_FILE
  98. if test 261 -ne `wc -c <'CHANGES'`; then
  99.     echo shar: \"'CHANGES'\" unpacked with wrong size!
  100. fi
  101. # end of 'CHANGES'
  102. fi
  103. if test -f 'mwcat.man' -a "${1}" != "-c" ; then 
  104.   echo shar: Will not clobber existing file \"'mwcat.man'\"
  105. else
  106. echo shar: Extracting \"'mwcat.man'\" \(1122 characters\)
  107. sed "s/^X//" >'mwcat.man' <<'END_OF_FILE'
  108. X.TH mwcat 1
  109. X.SH NAME
  110. Xmwcat \- print the contents of
  111. X\fIsqueeze\fBd
  112. Xfiles
  113. X.SH SYNTAX
  114. Xmwcat
  115. X[ options and files ]
  116. X.SH DESCRIPTION
  117. X.I mwcat
  118. Xapplies
  119. X.I unsqueeze
  120. Xto one or more files,
  121. Xprinting the result.
  122. XIt passes all options through to
  123. X.I unsqueeze.
  124. X.PP
  125. XRead the
  126. X.I squeeze
  127. Xand
  128. X.I unsqueeze
  129. Xdocumentation for a description of options and
  130. Xof the compression method.
  131. X.SH EXAMPLES
  132. XTo view foo.MW:
  133. X.PP
  134. X.EX
  135. Xmwcat foo | more
  136. X.EE
  137. X.PP
  138. XFor a display revealing common substrings (try it):
  139. X.PP
  140. X.EX
  141. Xmwcat -d~ foo | more
  142. X.EE
  143. X.SH DIAGNOSTICS
  144. X.TP
  145. X\fIfatal: must specify filenames; use unsqueeze for a filter\fB
  146. XSelf-explanatory.
  147. X.PP
  148. X.I unsqueeze
  149. Xwill print compression statistics if you specify
  150. X.B\-v.
  151. X.SH MACHINES
  152. X.I mwcat
  153. Xhas been tested on an Astronautics ZS-2
  154. Xrunning ZSUnix,
  155. Xa Convex C1 running Convex UNIX,
  156. Xand an HP9000 running HP-UX.
  157. X.SH FILES
  158. XNone.
  159. X.SH BUGS
  160. XNone known.
  161. X.SH RESTRICTIONS
  162. X.I mwcat
  163. Xis truly obnoxious in insisting upon a single MW suffix
  164. Xfor
  165. X\fIsqueeze\fBd
  166. Xfiles.
  167. X.SH VERSION
  168. Xmwcat, dated September 27, 1989.
  169. X.SH AUTHOR
  170. XCopyright 1989, Daniel J. Bernstein.
  171. X.SH "SEE ALSO"
  172. Xsqueeze(1),
  173. Xunsqueeze(1),
  174. Xsqz(1),
  175. Xsqzdir(1)
  176. END_OF_FILE
  177. if test 1122 -ne `wc -c <'mwcat.man'`; then
  178.     echo shar: \"'mwcat.man'\" unpacked with wrong size!
  179. fi
  180. # end of 'mwcat.man'
  181. fi
  182. if test -f 'squeeze.man' -a "${1}" != "-c" ; then 
  183.   echo shar: Will not clobber existing file \"'squeeze.man'\"
  184. else
  185. echo shar: Extracting \"'squeeze.man'\" \(4581 characters\)
  186. sed "s/^X//" >'squeeze.man' <<'END_OF_FILE'
  187. X.TH squeeze 1
  188. X.SH NAME
  189. Xsqueeze \- compress data with Miller\-Wegman encoding
  190. X.SH SYNTAX
  191. Xsqueeze
  192. X[
  193. X\fB\-eErRbBv\fI
  194. X] [
  195. X\fB\-ACHUVW\fI
  196. X]
  197. X.SH DESCRIPTION
  198. X.I squeeze
  199. Xcompresses its standard input
  200. Xand writes the result to its standard output.
  201. X\fIsqueeze\fBd
  202. Xfiles can be restored
  203. Xwith
  204. X\fIunsqueeze\fB.
  205. X.PP
  206. XOptions
  207. X.B ACHUVW
  208. Xprint the authorship notice,
  209. Xcopyright notice,
  210. Xhelp notice,
  211. Xshort usage summary,
  212. Xversion number,
  213. Xand warranty information respectively.
  214. X.PP
  215. X.I squeeze
  216. Xhas several flags:
  217. X.TP 12
  218. X.B -e
  219. XLeave an explicit end-of-file marker in the output.
  220. XIf you use this flag, you can add any
  221. Xsort of random garbage onto the end of the compressed data
  222. Xwithout affecting the decompressed form.
  223. X.TP
  224. X.B -E
  225. XDo not leave an end-of-file marker. This is the default.
  226. X.TP
  227. X.B -r
  228. XProduce ``randomized'' output.
  229. X.I squeeze
  230. Xwill use the time of day to introduce
  231. Xrandom bits of information
  232. Xinto the output.
  233. XNormally, for efficiency and so that
  234. X.I squeeze
  235. Xcan produce output before seeing the end of the input,
  236. Xthere must be slight output redundancy.
  237. XUnder
  238. X.B -r,
  239. Xthis redundancy disappears
  240. Xand almost all
  241. X\fIsqueeze\fBd
  242. Xtexts are possible.
  243. XSince
  244. X.I squeeze
  245. Xdoes not output a recognizable header,
  246. Xand since Miller-Wegman encoding is so good at removing
  247. Xredundancy,
  248. X.I squeeze -r
  249. Xis a very useful step before encryption.
  250. X(Caveat: the beginning of the output depends only
  251. Xon the beginning of the input, so you should make sure
  252. Xto
  253. X.I precede the uncompressed input
  254. X.I by unpredictable data
  255. Xbefore feeding it to
  256. X.I squeeze.)
  257. X.TP
  258. X.B -R
  259. XDo not randomize output. This is the default.
  260. X.TP
  261. X.B -b
  262. X.I squeeze
  263. Xmaintains a
  264. X``dictionary''
  265. Xof strings
  266. Xadapted to the data seen so far.
  267. XWhen
  268. X.I squeeze
  269. Xruns out of memory,
  270. Xit will adapt to the next
  271. X``block'' of the file
  272. Xby throwing out the dictionary and starting over.
  273. XThis is the default behavior and is given explicitly as
  274. X.B -b.
  275. X.TP
  276. X.B -B
  277. XGiven this flag,
  278. X.I squeeze
  279. Xwill simply freeze its old dictionary
  280. Xwhen it runs out of memory,
  281. Xrather than hope to do better on the
  282. Xsucceeding data.
  283. XThis will produce better (and faster) results
  284. Xif the first ``block'' of the file
  285. Xhas similar characteristics to the rest of the file.
  286. X.TP
  287. X.B -v
  288. X.I squeeze
  289. Xwill be ``verbose'' and report compression statistics
  290. Xto standard error.
  291. X.PP
  292. X.I squeeze
  293. Xuses Miller-Wegman encoding,
  294. Xa variant on Ziv-Lempel encoding.
  295. XThe amount of compression obtained depends on the size of the
  296. Xinput, the amount of memory
  297. X.I squeeze
  298. Xuses,
  299. Xand the distribution of common substrings.
  300. XTypically, text such as source code or English
  301. Xis reduced by 70\-80%.
  302. X.PP
  303. XIt is natural to compare
  304. X.I squeeze
  305. Xto
  306. X.I compress,
  307. Xwhich uses straightforward Ziv-Lempel encoding.
  308. XIn the author's experience,
  309. XMiller-Wegman encoding produces output
  310. X10\-40%
  311. Xsmaller than the corresponding Ziv-Lempel output;
  312. Xand the best case is much better.
  313. XOn the other hand,
  314. XMiller-Wegman encoding fares slightly worse
  315. Xon patternless data,
  316. Xand since it requires general string matching
  317. Xwhile Ziv-Lempel requires only a restricted type
  318. Xof string matching,
  319. X.I squeeze
  320. Xhas been somewhat slower than
  321. X.I compress
  322. Xin the author's tests.
  323. X.PP
  324. XFor files longer than a megabyte,
  325. X.I squeeze
  326. Xoften produces output under one third the size of the output from
  327. X.I compress,
  328. Xbut may do twice as much computation.
  329. XIt should also be noted that
  330. X.I squeeze
  331. Xis much more of a memory hog than
  332. X.I compress,
  333. Xsince it uses a more complex algorithm.
  334. X.PP
  335. XThe choices between
  336. X.B -e
  337. Xand
  338. X.B -E,
  339. Xand between
  340. X.B -b
  341. Xand
  342. X.B -B,
  343. Xchange the structure of the compressed file.
  344. XBe careful to select the same flags for
  345. X.I unsqueeze.
  346. X.SH DIAGNOSTICS
  347. X.TP
  348. X\fIIn:\fB xxx \fIchars  Out:\fB xxx \fIchars  Squeezed to:\fB xx%
  349. XThe utilizer of the computational machinery
  350. Xhas specified the ``verbose'' option
  351. Xto
  352. X.I squeeze
  353. Xvia the
  354. Xestablishment of the character v
  355. Xwithin an argument
  356. Xpreceded by a hyphen.
  357. X.TP
  358. X\fII am a filter, try sqz for squeezing files\fB
  359. XSelf-explanatory.
  360. X.SH MACHINES
  361. X.I squeeze
  362. Xhas been tested on an Astronautics ZS-2
  363. Xrunning ZSUnix,
  364. Xa Convex C1 running Convex UNIX,
  365. Xand an HP9000 running HP-UX.
  366. X.SH FILES
  367. XNone.
  368. X.SH BUGS
  369. XNone known.
  370. X.SH RESTRICTIONS
  371. X.I squeeze
  372. Xdoes not adapt to the amount of memory available;
  373. Xits memory use is set at compile time.
  374. X.PP
  375. X.I squeeze
  376. Xdoes not provide a more advanced blocking method.
  377. X.SH VERSION
  378. Xsqueeze version 1.711, dated October 28, 1989.
  379. X.SH AUTHOR
  380. XCopyright 1989, Daniel J. Bernstein.
  381. X.SH REFERENCES
  382. XVictor S. Miller,
  383. X"Data Compression Algorithms"
  384. Xin Proceedings of Symposia in Applied Mathematics
  385. XVolume 34, 1986.
  386. XA readable summary of major coding methods.
  387. X.SH "SEE ALSO"
  388. Xunsqueeze(1),
  389. Xsqz(1),
  390. Xsqzdir(1),
  391. Xmwcat(1),
  392. Xcompress(1)
  393. END_OF_FILE
  394. if test 4581 -ne `wc -c <'squeeze.man'`; then
  395.     echo shar: \"'squeeze.man'\" unpacked with wrong size!
  396. fi
  397. # end of 'squeeze.man'
  398. fi
  399. if test -f 'sqz.man' -a "${1}" != "-c" ; then 
  400.   echo shar: Will not clobber existing file \"'sqz.man'\"
  401. else
  402. echo shar: Extracting \"'sqz.man'\" \(1777 characters\)
  403. sed "s/^X//" >'sqz.man' <<'END_OF_FILE'
  404. X.TH sqz 1
  405. X.SH NAME
  406. Xsqz \- apply
  407. X.I squeeze
  408. Xto a file
  409. X.PP
  410. Xunsqz \- apply
  411. X.I unsqueeze
  412. Xto a file
  413. X.SH SYNTAX
  414. Xsqz
  415. X[ options and files ]
  416. X.PP
  417. Xunsqz
  418. X[ options and files ]
  419. X.SH DESCRIPTION
  420. X.I sqz
  421. Xuses
  422. X.I filterfile
  423. Xto apply
  424. X.I squeeze
  425. Xto one or more files.
  426. XIt passes all options through to
  427. X.I squeeze.
  428. X.I unsqz
  429. Xbears the same relation to
  430. X.I unsqeeze.
  431. X.PP
  432. XEach original file is removed;
  433. Xthe
  434. X\fIsqueeze\fBd
  435. Xdata is placed into a file having the same name
  436. Xwith a suffix of
  437. X\fIMW\fB.
  438. X.I sqz
  439. Xstrips this suffix from its input file names.
  440. X.PP
  441. XFile protections and access/modification times are preserved.
  442. X.PP
  443. X.I unsqz
  444. Xsimply reverses the operations of
  445. X.I sqz.
  446. X.PP
  447. XRead the
  448. X.I squeeze
  449. Xand
  450. X.I unsqueeze
  451. Xdocumentation for a description of options and
  452. Xof the compression method.
  453. X.SH DIAGNOSTICS
  454. X.TP
  455. X\fIfatal: must specify filenames; use squeeze for a filter\fB
  456. XSelf-explanatory.
  457. X.PP
  458. X.I squeeze
  459. Xand
  460. X.I unsqueeze
  461. Xwill print compression statistics if you specify
  462. X.B\-v.
  463. X.PP
  464. X.I filterfile
  465. Xmay produce error messages if
  466. Xa file does not exist or has more than one link,
  467. Xor if you move the file during
  468. Xthe operation.
  469. X.SH MACHINES
  470. X.I sqz
  471. Xand 
  472. X.I unsqz
  473. Xhave been tested on an Astronautics ZS-2
  474. Xrunning ZSUnix,
  475. Xa Convex C1 running Convex UNIX,
  476. Xand an HP9000 running HP-UX.
  477. X.SH FILES
  478. XNone.
  479. X.SH BUGS
  480. XNone known.
  481. X.SH RESTRICTIONS
  482. X.I sqz
  483. Xand
  484. X.I unsqz
  485. Xare truly obnoxious in insisting upon a single MW suffix
  486. Xfor
  487. X\fIsqueeze\fBd
  488. Xfiles.
  489. X.PP
  490. X.I sqz
  491. Xand
  492. X.I unsqz
  493. Xdo not provide for overwriting an existing file.
  494. X.PP
  495. XBecause
  496. Xthese programs are not integrated,
  497. Xthe error messages may seem a bit strange at times.
  498. X.SH VERSION
  499. Xsqz, dated September 27, 1989.
  500. X.PP
  501. Xunsqz, dated September 27, 1989.
  502. X.SH AUTHOR
  503. XCopyright 1989, Daniel J. Bernstein.
  504. X.SH "SEE ALSO"
  505. Xsqueeze(1),
  506. Xunsqueeze(1),
  507. Xsqzdir(1),
  508. Xmwcat(1),
  509. Xfilterfile(1)
  510. END_OF_FILE
  511. if test 1777 -ne `wc -c <'sqz.man'`; then
  512.     echo shar: \"'sqz.man'\" unpacked with wrong size!
  513. fi
  514. # end of 'sqz.man'
  515. fi
  516. if test -f 'sqzdir.man' -a "${1}" != "-c" ; then 
  517.   echo shar: Will not clobber existing file \"'sqzdir.man'\"
  518. else
  519. echo shar: Extracting \"'sqzdir.man'\" \(1964 characters\)
  520. sed "s/^X//" >'sqzdir.man' <<'END_OF_FILE'
  521. X.TH sqz 1
  522. X.SH NAME
  523. Xsqzdir \- apply
  524. X.I squeeze
  525. Xto a directory hierarchy
  526. X.PP
  527. Xunsqzdir \- apply
  528. X.I unsqueeze
  529. Xto a directory hierarchy
  530. X.SH SYNTAX
  531. Xsqzdir
  532. X[ options and directories ]
  533. X.PP
  534. Xunsqzdir
  535. X[ options and directories ]
  536. X.SH DESCRIPTION
  537. X.I sqzdir
  538. Xuses
  539. X.I find
  540. Xand
  541. X.I filterfile
  542. Xto apply
  543. X.I squeeze
  544. Xto one or more directories,
  545. Xpassing down through the entire tree beneath each directory.
  546. XIt passes all options through to
  547. X.I squeeze.
  548. X.I unsqzdir
  549. Xbears the same relation to
  550. X.I unsqeeze.
  551. X.PP
  552. XEach original file is removed;
  553. Xthe
  554. X\fIsqueeze\fBd
  555. Xdata is placed into a file having the same name
  556. Xwith a suffix of
  557. X\fIMW\fB.
  558. X.I sqzdir
  559. Xstrips this suffix from its input file names.
  560. X.PP
  561. XFile protections and access/modification times are preserved.
  562. X.PP
  563. X.I unsqzdir
  564. Xsimply reverses the operations of
  565. X.I sqzdir.
  566. X.PP
  567. XIf you do not specify a filename,
  568. X.I sqzdir
  569. Xand
  570. X.I unsqzdir
  571. Xassume the current directory.
  572. X.PP
  573. XRead the
  574. X.I squeeze
  575. Xand
  576. X.I unsqueeze
  577. Xdocumentation for a description of options and
  578. Xof the compression method.
  579. X.SH DIAGNOSTICS
  580. X.PP
  581. X.I squeeze
  582. Xand
  583. X.I unsqueeze
  584. Xwill print compression statistics if you specify
  585. X.B\-v.
  586. X.PP
  587. X.I filterfile
  588. Xmay produce error messages if
  589. Xa file does not exist or has more than one link,
  590. Xor if you move the file during
  591. Xthe operation.
  592. X.SH MACHINES
  593. X.I sqzdir
  594. Xand
  595. X.I unsqzdir
  596. Xhave been tested on an Astronautics ZS-2
  597. Xrunning ZSUnix,
  598. Xa Convex C1 running Convex UNIX,
  599. Xand an HP9000 running HP-UX.
  600. X.SH FILES
  601. XNone.
  602. X.SH BUGS
  603. XNone known.
  604. X.SH RESTRICTIONS
  605. X.I sqzdir
  606. Xand
  607. X.I unsqzdir
  608. Xare truly obnoxious in insisting upon a single MW suffix
  609. Xfor
  610. X\fIsqueeze\fBd
  611. Xfiles.
  612. X.PP
  613. X.I sqzdir
  614. Xand
  615. X.I unsqzdir
  616. Xdo not provide for overwriting an existing file.
  617. X.PP
  618. XBecause
  619. Xthese programs are not integrated,
  620. Xthe error messages may seem a bit strange at times.
  621. X.SH VERSION
  622. Xsqzdir, dated September 27, 1989.
  623. X.PP
  624. Xunsqzdir, dated September 27, 1989.
  625. X.SH AUTHOR
  626. XCopyright 1989, Daniel J. Bernstein.
  627. X.SH "SEE ALSO"
  628. Xsqueeze(1),
  629. Xunsqueeze(1),
  630. Xsqz(1),
  631. Xmwcat(1),
  632. Xfilterfile(1),
  633. Xfind(1)
  634. END_OF_FILE
  635. if test 1964 -ne `wc -c <'sqzdir.man'`; then
  636.     echo shar: \"'sqzdir.man'\" unpacked with wrong size!
  637. fi
  638. # end of 'sqzdir.man'
  639. fi
  640. if test -f 'unsqueeze.man' -a "${1}" != "-c" ; then 
  641.   echo shar: Will not clobber existing file \"'unsqueeze.man'\"
  642. else
  643. echo shar: Extracting \"'unsqueeze.man'\" \(3588 characters\)
  644. sed "s/^X//" >'unsqueeze.man' <<'END_OF_FILE'
  645. X.TH unsqueeze 1
  646. X.SH NAME
  647. Xunsqueeze \- decompress data squeezed with Miller\-Wegman encoding
  648. X.SH SYNTAX
  649. Xunsqueeze
  650. X[
  651. X\fB\-eErRbBv\fI
  652. X] [
  653. X\fB\-d\fIstring
  654. X] [
  655. X\fB\-ACHUVW\fI
  656. X]
  657. X.SH DESCRIPTION
  658. X.I unsqueeze
  659. Xdecompresses its standard input
  660. Xand writes the result to its standard output.
  661. XThe input should be a file compressed with
  662. X.I squeeze.
  663. X.PP
  664. XOptions
  665. X.B ACHUVW
  666. Xprint the authorship notice,
  667. Xcopyright notice,
  668. Xhelp notice,
  669. Xshort usage summary,
  670. Xversion number,
  671. Xand warranty information respectively.
  672. X.PP
  673. X.I unsqueeze
  674. Xhas several flags:
  675. X.TP 12
  676. X.B -e
  677. XExpect an explicit end-of-file marker in the output.
  678. X.TP
  679. X.B -E
  680. XDo not expect an explicit end-of-file marker. This is the default.
  681. X.TP
  682. X.B -r
  683. XAccept any input string, including
  684. X``randomized'' output from
  685. X.I squeeze.
  686. XThis is the default.
  687. X.TP
  688. X.B -R
  689. XComplain about randomized inputs.
  690. XThis will catch most inputs that come from
  691. X\fIsqueeze\fB -r;
  692. Xit will also tend to catch inputs that don't come
  693. Xfrom
  694. X.I squeeze
  695. Xat all.
  696. X.TP
  697. X.B -b
  698. XExpect ``blocked'' input and accept ``next block'' codes.
  699. XThis is the default.
  700. X.TP
  701. X.B -B
  702. XExpect unblocked input.
  703. X.TP
  704. X\fB-d\fIstring
  705. XInsert
  706. X.I string
  707. Xbetween output bunches.
  708. XIf you want to get a feel for the workings
  709. Xof Miller-Wegman compression, try this.
  710. X.TP
  711. X.B -v
  712. X.I unsqueeze
  713. Xwill be ``verbose'' and report compression statistics
  714. Xto standard error.
  715. X.PP
  716. XSee
  717. X.I squeeze(1)
  718. Xfor a discussion of the time-space tradeoff
  719. Xinvolved in using Miller-Wegman encoding rather than
  720. XZiv-Lempel encoding.
  721. XNote that
  722. X.I unsqueeze
  723. Xruns nearly as quickly as
  724. X.I uncompress,
  725. Xfor the same size decompressed text,
  726. Xand can run faster for huge texts.
  727. X.PP
  728. XThe choices between
  729. X.B -e
  730. Xand
  731. X.B -E,
  732. Xand between
  733. X.B -b
  734. Xand
  735. X.B -B,
  736. Xchange the structure of the compressed file.
  737. XBe careful to select the same flags as
  738. X.I squeeze
  739. Xwas given.
  740. X.SH DIAGNOSTICS
  741. X.TP 1.5i
  742. X.I bad (randomized) input
  743. XYou gave the flag
  744. X.B -R
  745. Xand the input cannot have come from
  746. X.I squeeze
  747. Xwith the same flags.
  748. X.TP
  749. X.I out of memory
  750. XThe file was
  751. X\fIsqueeze\fBd
  752. Xin much more memory than
  753. X.I unsqueeze
  754. Xhas available.
  755. X.TP
  756. X.I EOF not signalled?
  757. XYou gave the flag
  758. X.B -e
  759. Xbut the input did not signal end-of-file.
  760. X.TP
  761. X\fIIn:\fB xxx \fIchars  Out:\fB xxx \fIchars  Squeezed to:\fB xx%
  762. XThe utilizer of the computational machinery
  763. Xhas specified the ``verbose'' option
  764. Xto
  765. X.I unsqueeze
  766. Xvia the
  767. Xestablishment of the character v
  768. Xwithin an argument
  769. Xpreceded by a hyphen.
  770. X.TP
  771. X\fII am a filter, try unsqz for unsqueezing files\fB
  772. XSelf-explanatory.
  773. X.SH MACHINES
  774. X.I unsqueeze
  775. Xhas been tested on an Astronautics ZS-2
  776. Xrunning ZSUnix,
  777. Xa Convex C-1 running Convex UNIX,
  778. Xand an HP9000 running HP-UX.
  779. X.SH FILES
  780. XNone.
  781. X.SH BUGS
  782. XNone known.
  783. X.SH RESTRICTIONS
  784. X.I unsqueeze
  785. Xdoes not adapt to the amount of memory available;
  786. Xits memory use is set at compile time.
  787. X.PP
  788. XUnlike
  789. X.I uncompress,
  790. X.I unsqueeze
  791. Xcarefully checks bounds on its variables
  792. Xand cannot be made to loop.
  793. X(\fIuncompress\fB
  794. Xdepends upon receiving signal SEGV when it uses out-of-bounds
  795. Xvariables.)
  796. XFor efficiency,
  797. X.I unsqueeze
  798. Xmakes one exception
  799. Xthat could, conceivably, cause a segmentation fault.
  800. XThis exception can only happen for certain
  801. Xspecially constructed files of length at least
  802. Xhalf a billion bytes.
  803. XOf course, that doesn't excuse the author,
  804. Xwho begs forgiveness for this lapse of judgment.
  805. X.SH VERSION
  806. Xunsqueeze version 1.711, dated October 28, 1989.
  807. X.SH AUTHOR
  808. XCopyright 1989, Daniel J. Bernstein.
  809. X.SH REFERENCES
  810. XVictor S. Miller,
  811. X"Data Compression Algorithms"
  812. Xin Proceedings of Symposia in Applied Mathematics
  813. XVolume 34, 1986.
  814. XA readable summary of major coding methods.
  815. X.SH "SEE ALSO"
  816. Xsqueeze(1),
  817. Xsqz(1),
  818. Xsqzdir(1),
  819. Xmwcat(1),
  820. Xcompress(1)
  821. END_OF_FILE
  822. if test 3588 -ne `wc -c <'unsqueeze.man'`; then
  823.     echo shar: \"'unsqueeze.man'\" unpacked with wrong size!
  824. fi
  825. # end of 'unsqueeze.man'
  826. fi
  827. if test -f 'squeeze.c' -a "${1}" != "-c" ; then 
  828.   echo shar: Will not clobber existing file \"'squeeze.c'\"
  829. else
  830. echo shar: Extracting \"'squeeze.c'\" \(11779 characters\)
  831. sed "s/^X//" >'squeeze.c' <<'END_OF_FILE'
  832. X/*
  833. Xsqueeze.c: Adaptive data compression with Miller-Wegman method.
  834. X*/
  835. X
  836. X/* explicit blocking char? <-- */
  837. X/* go from file to file and delete old file... .M? .W? .S? */
  838. X/* alloc() instead of huge array? less obnoxious? */
  839. X/* maybe stick to shorts for codes? half the memory */
  840. X/* how else to reduce memory requirement? */
  841. X/* signals? */
  842. X/* LRU? I think not */
  843. X/* option to decompress instead? I think not */
  844. X/* needs option for not searching dictionary after memory freeze? no */
  845. X/* is transition through clearing table ok? yes */
  846. X/* other blocking methods? not yet */
  847. X/* trie at top levels? like first version? hmmm */
  848. X
  849. Xstatic char squeezeauthor[] =
  850. X"squeeze was written by Daniel J. Bernstein.\n\
  851. XInternet address: brnstnd@acf10.nyu.edu.\n\
  852. XThanks to Herbert J. Bernstein for suggesting the data structures used.\n";
  853. X
  854. Xstatic char squeezeversion[] = 
  855. X"squeeze version 1.711, October 28, 1989.\n\
  856. XCopyright (c) 1989, Daniel J. Bernstein.\n\
  857. XAll rights reserved.\n";
  858. X
  859. Xstatic char squeezecopyright[] =
  860. X"squeeze version 1.711, October 28, 1989.\n\
  861. XCopyright (c) 1989, Daniel J. Bernstein.\n\
  862. XAll rights reserved.\n\
  863. X\n\
  864. XYou are granted the following rights: A. To make copies of this work in\n\
  865. Xoriginal form, so long as (1) the copies are exact and complete; (2) the\n\
  866. Xcopies include the copyright notice, this paragraph, and the disclaimer\n\
  867. Xof warranty in their entirety. B. To distribute this work, or copies made\n\
  868. Xunder the provisions above, so long as (1) this is the original work and\n\
  869. Xnot a derivative form; (2) you do not charge a fee for copying or for\n\
  870. Xdistribution; (3) you ensure that the distributed form includes the\n\
  871. Xcopyright notice, this paragraph, and the disclaimer of warranty in their\n\
  872. Xentirety. These rights are temporary and revocable upon written, oral, or\n\
  873. Xother notice by Daniel J. Bernstein. This copyright notice shall be\n\
  874. Xgoverned by the laws of the state of New York.\n\
  875. X\n\
  876. XIf you have questions about squeeze or about this copyright notice,\n\
  877. Xor if you would like additional rights beyond those granted above,\n\
  878. Xplease feel free to contact the author at brnstnd@acf10.nyu.edu\n\
  879. Xon the Internet.\n";
  880. X
  881. Xstatic char squeezewarranty[] =
  882. X"To the extent permitted by applicable law, Daniel J. Bernstein disclaims\n\
  883. Xall warranties, explicit or implied, including but not limited to the\n\
  884. Ximplied warranties of merchantability and fitness for a particular purpose.\n\
  885. XDaniel J. Bernstein is not and shall not be liable for any damages,\n\
  886. Xincidental or consequential, arising from the use of this program, even\n\
  887. Xif you inform him of the possibility of such damages. This disclaimer\n\
  888. Xshall be governed by the laws of the state of New York.\n\
  889. X\n\
  890. XIn other words, use this program at your own risk.\n\
  891. X\n\
  892. XIf you have questions about squeeze or about this disclaimer of warranty,\n\
  893. Xplease feel free to contact the author at brnstnd@acf10.nyu.edu\n\
  894. Xon the Internet.\n";
  895. X
  896. Xstatic char squeezeusage[] =
  897. X"Usage: squeeze [ -eErRbBvACHUVW ]\n\
  898. XHelp:  squeeze -H\n";
  899. X
  900. Xstatic char squeezehelp[] =
  901. X"squeeze compresses its input and prints the result, using adaptive Miller-\n\
  902. XWegman encoding, a variation on Ziv-Lempel encoding. It usually produces\n\
  903. Xfiles 10-40%% shorter than compress does. To decompress, use unsqueeze.\n\
  904. X\n\
  905. Xsqueeze -A: print authorship notice\n\
  906. Xsqueeze -C: print copyright notice\n\
  907. Xsqueeze -H: print this notice\n\
  908. Xsqueeze -U: print short usage summary\n\
  909. Xsqueeze -V: print version number\n\
  910. Xsqueeze -W: print disclaimer of warranty\n\
  911. X\n\
  912. Xsqueeze [ -eErRbBv ]: compress\n\
  913. X  -e: explicitly indicate EOF\n\
  914. X  -E: do not explicitly indicate EOF (default)\n\
  915. X  -r: ``randomize'' output; useful before encryption\n\
  916. X  -R: do not randomize output (default)\n\
  917. X  -b: readapt to next block when out of memory (default)\n\
  918. X  -B: freeze working adaptation when out of memory\n\
  919. X  -v: announce compression results (``verbose'')\n\
  920. X\n\
  921. XIf you have questions about or suggestions for squeeze, please feel free\n\
  922. Xto contact the author, Daniel J. Bernstein, at brnstnd@acf10.nyu.edu\n\
  923. Xon the Internet.\n";
  924. X
  925. X#include <stdio.h>
  926. X#include <sys/time.h>
  927. X
  928. X#define ALPHABET 256
  929. X#define BUFSIZE 300000
  930. X#define DICTSIZE BUFSIZE
  931. X#define MOD 354621
  932. X#define OUTBUFSIZE 2000
  933. X
  934. Xint flagrandom = 0;
  935. Xint flageof = 0;
  936. Xint flagblocking = 1; /* sigh */
  937. Xint flagverbose = 0;
  938. X
  939. Xint numberin = 0;
  940. Xint numberout = 0;
  941. X
  942. Xint table[MOD];
  943. X
  944. Xint parent[DICTSIZE];
  945. Xint num[DICTSIZE];
  946. Xint next[DICTSIZE];
  947. X
  948. X#define morehash(curhash,ch) ( ( curhash * 256 + ch + 1) % MOD )
  949. X/* Rules on hash: For same curhash and different ch, must produce
  950. Xdifferent hash. Must produce values between 0 and MOD - 1.
  951. X*/
  952. X
  953. Xcleartable()
  954. X{
  955. X register int h;
  956. X
  957. X for (h = 0;h < MOD;)
  958. X   table[h++] = 0;
  959. X}
  960. X
  961. Xgoaheadandbeverbose()
  962. X{
  963. X fprintf(stderr,"In: %d chars  Out: %d chars  Squeezed to: %d%%\n",
  964. X numberin,numberout,(100 * numberout + numberin / 2) / numberin);
  965. X}
  966. X
  967. Xinitdictionary()
  968. X{
  969. X register int ch;
  970. X
  971. X for (ch = 0;ch < ALPHABET;ch++)
  972. X  {
  973. X   parent[ch + 1] = 0;
  974. X   num[ch + 1] = ch;
  975. X   next[ch + 1] = 0;
  976. X   table[morehash(0,ch)] = ch + 1;
  977. X  }
  978. X}
  979. X
  980. Xint y[55];
  981. Xint j;
  982. Xint k;
  983. X
  984. Xinitrandom()
  985. X{
  986. X struct timeval t;
  987. X
  988. X gettimeofday(&t,(struct timezone *) NULL);
  989. X for (j = 0;j < 20;j++)
  990. X   y[j] = ((t.tv_usec >> j) + (t.tv_sec >> j)) % 2;
  991. X gettimeofday(&t,(struct timezone *) NULL);
  992. X for (j = 0;j < 20;j++)
  993. X   y[j + 20] = (t.tv_usec >> j) % 2;
  994. X y[54] = 1;
  995. X j = 24;
  996. X k = 0;
  997. X}
  998. X
  999. Xint randombit()
  1000. X{
  1001. X j = (j + 54) % 55;
  1002. X k = (k + 54) % 55;
  1003. X return(y[k] = y[k] ^ y[j]);
  1004. X}
  1005. X
  1006. X/* input routines */
  1007. X
  1008. Xunsigned char buf[BUFSIZE];
  1009. Xint bufstart = 0;
  1010. Xint bufend = 0;
  1011. X
  1012. X/* getchar() with readable buffer */
  1013. X#define inchar() ( bufstart != bufend ? ((result = buf[bufstart]), \
  1014. X  (bufstart = (bufstart + 1) % BUFSIZE), result) : ((result = getchar()), \
  1015. X  result == EOF ? EOF : ((buf[bufstart] = result = (unsigned char) result), \
  1016. X  (bufend = (bufstart = (bufstart + 1) % BUFSIZE)), result )))
  1017. X/* uses register int result --- down in main */
  1018. X
  1019. X/* reread last n buffered characters */
  1020. X#define inrepeat(n) { bufstart = (bufstart + BUFSIZE - (n)) % BUFSIZE; }
  1021. X/* stupid C mod... note: need not check n > BUFSIZE since n < DICTSIZE */
  1022. X
  1023. X/* un-reread n buffered characters */
  1024. X#define uninrepeat(n) { bufstart = (bufstart + (n)) % BUFSIZE; }
  1025. X/* stupid C mod... note: need not check n > BUFSIZE since n < DICTSIZE */
  1026. X
  1027. X/* output routines */
  1028. X
  1029. Xint outn[OUTBUFSIZE];
  1030. Xint outb[OUTBUFSIZE];
  1031. Xint outbitpos = 0;
  1032. Xint outword = 0;
  1033. Xint outbuf = 0;
  1034. X
  1035. Xoutnum(ch,max)
  1036. Xregister int ch;
  1037. Xregister int max;
  1038. X{
  1039. X register int m = (max + flageof + flagblocking) >> 8;
  1040. X   /* skipping eight steps because max >= 128 */
  1041. X
  1042. X outb[outbuf] = 8;
  1043. X while (m)
  1044. X   outb[outbuf]++, m >>= 1;
  1045. X
  1046. X if (flagrandom)
  1047. X   if (ch < (1 << outb[outbuf]) - max - flageof - flagblocking - 1)
  1048. X     if (randombit())
  1049. X       ch += (max + flageof + flagblocking + 1);
  1050. X outn[outbuf] = ch;
  1051. X outbuf++;
  1052. X if (outbuf == OUTBUFSIZE)
  1053. X  {
  1054. X   for (outbuf = 0;outbuf < OUTBUFSIZE;outbuf++)
  1055. X    {
  1056. X     outword += (outn[outbuf] << outbitpos);
  1057. X     outbitpos += outb[outbuf];
  1058. X     while (outbitpos > 7)
  1059. X      {
  1060. X       putchar((outword & 255));
  1061. X       numberout++;
  1062. X       outword >>= 8;
  1063. X       outbitpos -= 8;
  1064. X      }
  1065. X    }
  1066. X   outbuf = 0;
  1067. X  }
  1068. X}
  1069. X
  1070. Xoutfinish()
  1071. X{
  1072. X register int i;
  1073. X
  1074. X for (i = 0;i < outbuf;i++)
  1075. X  {
  1076. X   outword += (outn[i] << outbitpos);
  1077. X   outbitpos += outb[i];
  1078. X   while (outbitpos > 7)
  1079. X    {
  1080. X     putchar((outword & 255));
  1081. X     numberout++;
  1082. X     outword >>= 8;
  1083. X     outbitpos -= 8;
  1084. X    }
  1085. X  }
  1086. X if (flagrandom)
  1087. X  {
  1088. X   while (outbitpos < 7)
  1089. X    {
  1090. X     outword += (randombit() << outbitpos);
  1091. X     outbitpos++; /* fill the final byte with random bits */
  1092. X    }
  1093. X  }
  1094. X putchar(outword); /* the final byte */
  1095. X numberout++;
  1096. X}
  1097. X
  1098. X/* the real stuff */
  1099. X
  1100. Xmain(argc,argv,envp)
  1101. Xint argc;
  1102. Xchar *argv[];
  1103. Xchar *envp[];
  1104. X{
  1105. X register int ch;
  1106. X register int maxnum;
  1107. X register int maxnode;
  1108. X register int i;
  1109. X register int match;
  1110. X register int matchlen;
  1111. X register int curhash;
  1112. X register int dictmatch;
  1113. X register int dictmatchlen;
  1114. X register int dictmatchhash;
  1115. X register int oldmatch;
  1116. X register int oldmatchhash;
  1117. X register int result; /* for inchar() */
  1118. X
  1119. X while (*(++argv))
  1120. X   if (**argv == '-')
  1121. X     while (*(++(*argv)))
  1122. X       switch(**argv)
  1123. X        {
  1124. X         case 'e': flageof = 1; break;
  1125. X         case 'E': flageof = 0; break;
  1126. X         case 'r': flagrandom = 1; break;
  1127. X         case 'R': flagrandom = 0; break;
  1128. X     case 'b': flagblocking = 1; break;
  1129. X     case 'B': flagblocking = 0; break;
  1130. X     case 'v': flagverbose = 1; break;
  1131. X     case 'A': printf(squeezeauthor); exit(0);
  1132. X         case 'C': printf(squeezecopyright); exit(0);
  1133. X         case 'V': printf(squeezeversion); exit(0);
  1134. X         case 'W': printf(squeezewarranty); exit(0);
  1135. X         case 'H': printf(squeezehelp); exit(0);
  1136. X         case 'U': printf(squeezeusage); exit(0);
  1137. X         default: ;
  1138. X        }
  1139. X   else
  1140. X    {
  1141. X     fprintf(stderr,"squeeze: I am a filter, try sqz for squeezing files\n");
  1142. X     exit(1);
  1143. X    }
  1144. X
  1145. X if (flagrandom)
  1146. X   initrandom();
  1147. X
  1148. Xstart_over:
  1149. X initdictionary();
  1150. X maxnum = ALPHABET - 1;
  1151. X maxnode = ALPHABET;
  1152. X
  1153. X if ((ch = inchar()) == EOF)
  1154. X  {
  1155. X   if (flageof) /* can't leave without saying goodbye! */
  1156. X     outnum(maxnum + 1,maxnum);
  1157. X   outfinish();
  1158. X   if (flagverbose)
  1159. X     goaheadandbeverbose();
  1160. X   exit(0);
  1161. X  }
  1162. X outnum(ch,maxnum);
  1163. X numberin++;
  1164. X oldmatch = table[oldmatchhash = morehash(0,ch)];
  1165. X
  1166. X for (;;)
  1167. X  {
  1168. X   match = matchlen = curhash = 0;
  1169. X   dictmatch = dictmatchlen = dictmatchhash = 0;
  1170. X
  1171. X   for (;;)
  1172. X    {
  1173. Xtop_of_loop:
  1174. X     if ((ch = inchar()) == EOF)
  1175. X       if (matchlen == 0)
  1176. X    {
  1177. X     if (flageof) /* can't leave without saying goodbye! */
  1178. X       outnum(maxnum + 1,maxnum);
  1179. X     outfinish();
  1180. X     if (flagverbose)
  1181. X       goaheadandbeverbose();
  1182. X     exit(0);
  1183. X    }
  1184. X       else
  1185. X     break;
  1186. X     curhash = morehash(curhash,ch);
  1187. X     for (i = table[curhash];i;i = next[i])
  1188. X       if (parent[i] == match)
  1189. X    {
  1190. X     match = i; matchlen++;
  1191. X     if (num[i] != -1)
  1192. X      {
  1193. X       dictmatch = match;
  1194. X       dictmatchlen = matchlen;
  1195. X       dictmatchhash = curhash;
  1196. X      }
  1197. X     goto top_of_loop; /* I wish C had real control structures */
  1198. X    }
  1199. X     /* i is zero; we didn't match on this character. */
  1200. X     break; /* could stick the reread(1) here */
  1201. X    }
  1202. X   
  1203. X   numberin += dictmatchlen;
  1204. X   outnum(num[dictmatch],maxnum);
  1205. X   inrepeat((ch != EOF) + matchlen);
  1206. X   /* Reread first dictmatchlen and extend onto laststring. */
  1207. X   match = oldmatch;
  1208. X   curhash = oldmatchhash;
  1209. X   while (dictmatchlen-- > 0)
  1210. X    {
  1211. X     ch = inchar(); /* can't be EOF---repetition of previous */
  1212. X     curhash = morehash(curhash,ch);
  1213. X     for (i = table[curhash];i;i = next[i])
  1214. X       if (parent[i] == match)
  1215. X    {
  1216. X     match = i;
  1217. X     break;
  1218. X    }
  1219. X     if (!i) /* we're out of the tree---zoom on down! */
  1220. X      {
  1221. X       if (maxnode + dictmatchlen + 1 < DICTSIZE)
  1222. X    {
  1223. X     maxnode++;
  1224. X         parent[maxnode] = match;
  1225. X         next[maxnode] = table[curhash];
  1226. X         num[maxnode] = -1;
  1227. X         match = maxnode;
  1228. X         table[curhash] = maxnode;
  1229. X         while (dictmatchlen-- > 0)
  1230. X      {
  1231. X       ch = inchar(); /* can't be EOF */
  1232. X       curhash = morehash(curhash,ch);
  1233. X       maxnode++;
  1234. X       parent[maxnode] = match;
  1235. X       next[maxnode] = table[curhash];
  1236. X           num[maxnode] = -1;
  1237. X       match = maxnode;
  1238. X           table[curhash] = maxnode;
  1239. X      }
  1240. X         break;
  1241. X    }
  1242. X       else
  1243. X    {
  1244. X     /* oh, dear, we've run out of memory. */
  1245. X     maxnode = DICTSIZE;
  1246. X     uninrepeat(dictmatchlen);
  1247. X     dictmatchlen = 0; /* is this necessary? */
  1248. X     if (flagblocking) /* let's start over! */
  1249. X      {
  1250. X       outnum(maxnum + flageof + 2,maxnum + 1);
  1251. X       cleartable();
  1252. X       goto start_over; /* I wish C had real control structures */
  1253. X      }
  1254. X     break;
  1255. X    }
  1256. X      }
  1257. X    }
  1258. X   maxnum++;
  1259. X   if (maxnode < DICTSIZE)
  1260. X     if (num[match] == -1)
  1261. X       num[match] = maxnum;
  1262. X     else /* oops, a conflict */
  1263. X       if (flagrandom)
  1264. X         if (randombit())
  1265. X       num[match] = maxnum;
  1266. X   /* The other repeated inchars are saved for the next match. */
  1267. X   oldmatch = dictmatch;
  1268. X   oldmatchhash = dictmatchhash;
  1269. X  }
  1270. X}
  1271. END_OF_FILE
  1272. if test 11779 -ne `wc -c <'squeeze.c'`; then
  1273.     echo shar: \"'squeeze.c'\" unpacked with wrong size!
  1274. fi
  1275. # end of 'squeeze.c'
  1276. fi
  1277. if test -f 'unsqueeze.c' -a "${1}" != "-c" ; then 
  1278.   echo shar: Will not clobber existing file \"'unsqueeze.c'\"
  1279. else
  1280. echo shar: Extracting \"'unsqueeze.c'\" \(7995 characters\)
  1281. sed "s/^X//" >'unsqueeze.c' <<'END_OF_FILE'
  1282. X/*
  1283. Xunsqeeze.c: Adaptive data decompression with Miller-Wegman method.
  1284. X*/
  1285. X
  1286. X/* perhaps a memoryfreeze state bit to delay the out-of-memory? */
  1287. X/* go from file to file and delete old file... .M? .W? .S? */
  1288. X/* alloc() instead of huge array? less obnoxious? */
  1289. X/* stick to shorts? */
  1290. X/* signals? */
  1291. X/* option to compress instead? I think not */
  1292. X/* concatenate strings at low levels? not worth it---or is it? */
  1293. X
  1294. Xstatic char unsqueezeauthor[] =
  1295. X"unsqueeze was written by Daniel J. Bernstein.\n\
  1296. XInternet address: brnstnd@acf10.nyu.edu.\n";
  1297. X
  1298. Xstatic char unsqueezeversion[] = 
  1299. X"unsqueeze version 1.711, October 28, 1989.\n\
  1300. XCopyright (c) 1989, Daniel J. Bernstein.\n\
  1301. XAll rights reserved.\n";
  1302. X
  1303. Xstatic char unsqueezecopyright[] =
  1304. X"unsqueeze version 1.711, October 28, 1989.\n\
  1305. XCopyright (c) 1989, Daniel J. Bernstein.\n\
  1306. XAll rights reserved.\n\
  1307. X\n\
  1308. XYou are granted the following rights: A. To make copies of this work in\n\
  1309. Xoriginal form, so long as (1) the copies are exact and complete; (2) the\n\
  1310. Xcopies include the copyright notice, this paragraph, and the disclaimer\n\
  1311. Xof warranty in their entirety. B. To distribute this work, or copies made\n\
  1312. Xunder the provisions above, so long as (1) this is the original work and\n\
  1313. Xnot a derivative form; (2) you do not charge a fee for copying or for\n\
  1314. Xdistribution; (3) you ensure that the distributed form includes the\n\
  1315. Xcopyright notice, this paragraph, and the disclaimer of warranty in their\n\
  1316. Xentirety. These rights are temporary and revocable upon written, oral, or\n\
  1317. Xother notice by Daniel J. Bernstein. This copyright notice shall be\n\
  1318. Xgoverned by the laws of the state of New York.\n\
  1319. X\n\
  1320. XIf you have questions about unsqueeze or about this copyright notice,\n\
  1321. Xor if you would like additional rights beyond those granted above,\n\
  1322. Xplease feel free to contact the author at brnstnd@acf10.nyu.edu\n\
  1323. Xon the Internet.\n";
  1324. X
  1325. Xstatic char unsqueezewarranty[] =
  1326. X"To the extent permitted by applicable law, Daniel J. Bernstein disclaims\n\
  1327. Xall warranties, explicit or implied, including but not limited to the\n\
  1328. Ximplied warranties of merchantability and fitness for a particular purpose.\n\
  1329. XDaniel J. Bernstein is not and shall not be liable for any damages,\n\
  1330. Xincidental or consequential, arising from the use of this program, even\n\
  1331. Xif you inform him of the possibility of such damages. This disclaimer\n\
  1332. Xshall be governed by the laws of the state of New York.\n\
  1333. X\n\
  1334. XIn other words, use this program at your own risk.\n\
  1335. X\n\
  1336. XIf you have questions about unsqueeze or about this disclaimer of warranty,\n\
  1337. Xplease feel free to contact the author at brnstnd@acf10.nyu.edu\n\
  1338. Xon the Internet.\n";
  1339. X
  1340. Xstatic char unsqueezeusage[] =
  1341. X"Usage: unsqueeze [ -eErRbBACHUVW ] [ -dstring ]\n\
  1342. XHelp:  unsqueeze -H\n";
  1343. X
  1344. Xstatic char unsqueezehelp[] =
  1345. X"unsqueeze decompresses its input and prints the result. The input is a\n\
  1346. Xfile compressed with squeeze, which uses adaptive Miller-Wegman encoding.\n\
  1347. X\n\
  1348. Xunsqueeze -A: print authorship notice\n\
  1349. Xunsqueeze -C: print copyright notice\n\
  1350. Xunsqueeze -H: print this notice\n\
  1351. Xunsqueeze -U: print short usage summary\n\
  1352. Xunsqueeze -V: print version number\n\
  1353. Xunsqueeze -W: print disclaimer of warranty\n\
  1354. X\n\
  1355. Xunsqueeze [ -eErRbBdv ]: decompress\n\
  1356. X  -e: look for explicit indication of EOF\n\
  1357. X  -E: don't look for explicit EOF (default)\n\
  1358. X  -r: accept ``randomized'' input (default)\n\
  1359. X  -R: do not accept randomized input\n\
  1360. X  -b: assume input is ``blocked'' (default)\n\
  1361. X  -B: assume input is not blocked\n\
  1362. X  -dstring: display string between output bunches, for debugging\n\
  1363. X  -v: announce decompression results (``verbose'')\n\
  1364. X\n\
  1365. XIf you have questions about or suggestions for unsqueeze, please feel free\n\
  1366. Xto contact the author, Daniel J. Bernstein, at brnstnd@acf10.nyu.edu\n\
  1367. Xon the Internet.\n";
  1368. X
  1369. X#include <stdio.h>
  1370. X
  1371. X#define ALPHABET 256
  1372. X#define DICTSIZE 2000000
  1373. X#define STACKSIZE 50000
  1374. X
  1375. Xint flageof = 0;
  1376. Xint flagrandom = 1;
  1377. Xint flagdisplay = 0;
  1378. Xint flagblocking = 1;
  1379. Xint flagverbose = 0;
  1380. X
  1381. Xint numberin = 0;
  1382. Xint numberout = 0;
  1383. X
  1384. Xint startch;
  1385. Xint d[DICTSIZE]; /* dictionary in normal form */
  1386. X
  1387. Xint stack[STACKSIZE];
  1388. X
  1389. Xgoaheadandbeverbose()
  1390. X{
  1391. X fprintf(stderr,"In: %d chars  Out: %d chars  Unsqueezed from: %d%%\n",
  1392. X numberin,numberout,(100 * numberin + numberout / 2) / numberout);
  1393. X}
  1394. X
  1395. Xoutput(ch)
  1396. Xregister int ch;
  1397. X{
  1398. X register int stackpos = 1;
  1399. X
  1400. X stack[0] = ch;
  1401. X while (stackpos)
  1402. X  {
  1403. X   ch = stack[--stackpos];
  1404. X   while (ch >= ALPHABET)
  1405. X    {
  1406. X     stack[stackpos++] = d[ch];
  1407. X     ch = (ch == ALPHABET ? startch : d[ch - 1]); /* tail recursion */
  1408. X    }
  1409. X   putchar((char) ch);
  1410. X   numberout++;
  1411. X  }
  1412. X}
  1413. X
  1414. X/* input routines */
  1415. X
  1416. X#define INBUFSIZE 2000
  1417. X
  1418. Xint inbuf[INBUFSIZE];
  1419. Xint inbufnum = INBUFSIZE;
  1420. Xint inbufstart = INBUFSIZE;
  1421. Xint inword = 0;
  1422. Xint inwordbits = 0;
  1423. X
  1424. Xint inchar(max)
  1425. Xregister int max;
  1426. X{
  1427. X register int result;
  1428. X register int inb = 8;
  1429. X
  1430. X max = (max + flageof + flagblocking) >> 8;
  1431. X   /* skipping eight steps because max >= 128 */
  1432. X
  1433. X while (max)
  1434. X   inb++, max >>= 1;
  1435. X
  1436. X while (inb > inwordbits)
  1437. X  {
  1438. X   if (inbufstart == inbufnum)
  1439. X    {
  1440. X     if (inbufnum == INBUFSIZE)
  1441. X      {
  1442. X       for (inbufnum = 0;inbufnum < INBUFSIZE;inbufnum++)
  1443. X    {
  1444. X         if ((inbuf[inbufnum] = getchar()) == EOF)
  1445. X       break;
  1446. X     else
  1447. X           numberin++;
  1448. X    }
  1449. X       inbufstart = 0;
  1450. X      }
  1451. X     if (inbufstart == inbufnum) /* end of file! */
  1452. X       return(EOF);
  1453. X    }
  1454. X   inword += inbuf[inbufstart++] << inwordbits;
  1455. X   inwordbits += 8;
  1456. X  }
  1457. X result = inword % (1 << inb);
  1458. X inword >>= inb;
  1459. X inwordbits -= inb;
  1460. X return(result);
  1461. X}
  1462. X
  1463. Xmain(argc,argv,envp)
  1464. Xint argc;
  1465. Xchar *argv[];
  1466. Xchar *envp[];
  1467. X{
  1468. X register int ch;
  1469. X register int max;
  1470. X register char *display;
  1471. X
  1472. X while (*(++argv))
  1473. X   if (**argv == '-')
  1474. X     while (*(++(*argv)))
  1475. X       switch(**argv)
  1476. X        {
  1477. X         case 'e': flageof = 1; break;
  1478. X         case 'E': flageof = 0; break;
  1479. X         case 'r': flagrandom = 1; break;
  1480. X         case 'R': flagrandom = 0; break;
  1481. X     case 'b': flagblocking = 1; break;
  1482. X     case 'B': flagblocking = 0; break;
  1483. X     case 'd': flagdisplay = 1; display = *argv + 1;
  1484. X           while (*(++(*argv))) /* null */ ;
  1485. X           --(*argv); break; /* we want breakbreak here */
  1486. X     case 'v': flagverbose = 1; break;
  1487. X         case 'A': printf(unsqueezeauthor); exit(0);
  1488. X         case 'C': printf(unsqueezecopyright); exit(0);
  1489. X         case 'V': printf(unsqueezeversion); exit(0);
  1490. X         case 'W': printf(unsqueezewarranty); exit(0);
  1491. X         case 'H': printf(unsqueezehelp); exit(0);
  1492. X         case 'U': printf(unsqueezeusage); exit(0);
  1493. X         default: ;
  1494. X        }
  1495. X   else
  1496. X    {
  1497. X     fprintf(stderr,
  1498. X       "unsqueeze: I am a filter, try unsqz for unsqueezing files\n");
  1499. X     exit(1);
  1500. X    }
  1501. X
  1502. Xstart_over:
  1503. X max = ALPHABET - 1; /* last spot in dictionary */
  1504. X
  1505. X if ((ch = inchar(max)) != EOF)
  1506. X  {
  1507. X   if (ch > max + flageof + flagblocking)
  1508. X     if (flagrandom)
  1509. X       ch = ch % (max + flageof + flagblocking + 1);
  1510. X     else
  1511. X       {
  1512. X        fprintf(stderr,"unsqueeze: bad (randomized?) input\n");
  1513. X        exit(1);
  1514. X       }
  1515. X   if (flageof && (ch == max + 1)) /* EOF signalled! */
  1516. X     goto eof_signalled;
  1517. X   if (flagblocking && (ch == max + flageof + 1))
  1518. X     goto start_over;
  1519. X   startch = ch;
  1520. X   output(ch);
  1521. X   if (flagdisplay)
  1522. X     printf(display);
  1523. X   while ((ch = inchar(max)) != EOF)
  1524. X    {
  1525. X     if (max >= DICTSIZE)
  1526. X      {
  1527. X       fprintf(stderr,"unsqueeze: not enough memory\n");
  1528. X       exit(1);
  1529. X      }
  1530. X     if (ch > max + flageof + flagblocking)
  1531. X       if (flagrandom)
  1532. X     ch = ch % (max + flageof + flagblocking + 1);
  1533. X       else
  1534. X    {
  1535. X     fprintf(stderr,"unsqueeze: bad (randomized?) input\n");
  1536. X     exit(1);
  1537. X    }
  1538. X     if (flageof && (ch == max + 1)) /* EOF signalled! */
  1539. X       goto eof_signalled;
  1540. X     if (flagblocking && (ch == max + flageof + 1))
  1541. X       goto start_over;
  1542. X     d[++max] = ch;
  1543. X     output(ch);
  1544. X     if (flagdisplay)
  1545. X       printf(display);
  1546. X    }
  1547. X  }
  1548. X if (flageof) /* EOF not signalled? */
  1549. X  {
  1550. X   fprintf(stderr,"unsqueeze: EOF not signalled?\n");
  1551. X   if (flagverbose)
  1552. X     goaheadandbeverbose();
  1553. X   exit(1);
  1554. X  }
  1555. Xeof_signalled:
  1556. X if (flagverbose)
  1557. X   goaheadandbeverbose();
  1558. X exit(0);
  1559. X}
  1560. END_OF_FILE
  1561. if test 7995 -ne `wc -c <'unsqueeze.c'`; then
  1562.     echo shar: \"'unsqueeze.c'\" unpacked with wrong size!
  1563. fi
  1564. # end of 'unsqueeze.c'
  1565. fi
  1566. if test -f 'sqz' -a "${1}" != "-c" ; then 
  1567.   echo shar: Will not clobber existing file \"'sqz'\"
  1568. else
  1569. echo shar: Extracting \"'sqz'\" \(405 characters\)
  1570. sed "s/^X//" >'sqz' <<'END_OF_FILE'
  1571. X#!/bin/sh
  1572. XOPTIONS=
  1573. XFILES=
  1574. XFILTERFILEEXT=MW; export FILTERFILEEXT
  1575. Xfor ARG
  1576. Xdo
  1577. X  case "$ARG" in
  1578. X    -*) OPTIONS="$OPTIONS $ARG";;
  1579. X    *) ARG="`expr $ARG : '\(.*\)\.MW' '|' $ARG`"
  1580. X       FILES="$FILES $ARG";;
  1581. X  esac
  1582. Xdone
  1583. Xif test -z "$FILES"
  1584. Xthen
  1585. X  echo 'sqz: fatal: must specify filenames; use squeeze for a filter' 1>&2
  1586. X  exit 1
  1587. Xfi
  1588. Xset $FILES
  1589. Xfor ARG
  1590. Xdo
  1591. X  filterfile -dpt "$ARG" squeeze $OPTIONS
  1592. Xdone
  1593. Xexit 0
  1594. END_OF_FILE
  1595. if test 405 -ne `wc -c <'sqz'`; then
  1596.     echo shar: \"'sqz'\" unpacked with wrong size!
  1597. fi
  1598. chmod +x 'sqz'
  1599. # end of 'sqz'
  1600. fi
  1601. if test -f 'sqzdir' -a "${1}" != "-c" ; then 
  1602.   echo shar: Will not clobber existing file \"'sqzdir'\"
  1603. else
  1604. echo shar: Extracting \"'sqzdir'\" \(381 characters\)
  1605. sed "s/^X//" >'sqzdir' <<'END_OF_FILE'
  1606. X#!/bin/sh
  1607. XOPTIONS=
  1608. XFILES=
  1609. XFILTERFILEEXT=MW; export FILTERFILEEXT
  1610. Xfor ARG
  1611. Xdo
  1612. X  case "$ARG" in
  1613. X    -*) OPTIONS="$OPTIONS $ARG";;
  1614. X    *) FILES="$FILES $ARG";;
  1615. X  esac
  1616. Xdone
  1617. Xif test -z "$FILES"
  1618. Xthen
  1619. X  FILES=.
  1620. Xfi
  1621. Xset $FILES
  1622. Xfind $@ -type f -links 1 \! \( -name '*.MW' -o -name '.*.MW' \) -exec filterfile -dpt {} squeeze $OPTIONS \;
  1623. X# stupid find, thinks * doesn't match dot files
  1624. Xexit 0
  1625. END_OF_FILE
  1626. if test 381 -ne `wc -c <'sqzdir'`; then
  1627.     echo shar: \"'sqzdir'\" unpacked with wrong size!
  1628. fi
  1629. chmod +x 'sqzdir'
  1630. # end of 'sqzdir'
  1631. fi
  1632. if test -f 'unsqz' -a "${1}" != "-c" ; then 
  1633.   echo shar: Will not clobber existing file \"'unsqz'\"
  1634. else
  1635. echo shar: Extracting \"'unsqz'\" \(415 characters\)
  1636. sed "s/^X//" >'unsqz' <<'END_OF_FILE'
  1637. X#!/bin/sh
  1638. XOPTIONS=
  1639. XFILES=
  1640. XFILTERFILEEXT=.MW; export FILTERFILEEXT
  1641. Xfor ARG
  1642. Xdo
  1643. X  case "$ARG" in
  1644. X    -*) OPTIONS="$OPTIONS $ARG";;
  1645. X    *) ARG="`expr $ARG : '\(.*\.MW\)' '|' $ARG.MW`"
  1646. X       FILES="$FILES $ARG";;
  1647. X  esac
  1648. Xdone
  1649. Xif test -z "$FILES"
  1650. Xthen
  1651. X  echo 'unsqz: fatal: must specify filenames; use unsqueeze for a filter' 1>&2
  1652. X  exit 1
  1653. Xfi
  1654. Xset $FILES
  1655. Xfor ARG
  1656. Xdo
  1657. X  filterfile -dpt "$ARG" unsqueeze $OPTIONS
  1658. Xdone
  1659. Xexit 0
  1660. END_OF_FILE
  1661. if test 415 -ne `wc -c <'unsqz'`; then
  1662.     echo shar: \"'unsqz'\" unpacked with wrong size!
  1663. fi
  1664. chmod +x 'unsqz'
  1665. # end of 'unsqz'
  1666. fi
  1667. if test -f 'unsqzdir' -a "${1}" != "-c" ; then 
  1668.   echo shar: Will not clobber existing file \"'unsqzdir'\"
  1669. else
  1670. echo shar: Extracting \"'unsqzdir'\" \(381 characters\)
  1671. sed "s/^X//" >'unsqzdir' <<'END_OF_FILE'
  1672. X#!/bin/sh
  1673. XOPTIONS=
  1674. XFILES=
  1675. XFILTERFILEEXT=.MW; export FILTERFILEEXT
  1676. Xfor ARG
  1677. Xdo
  1678. X  case "$ARG" in
  1679. X    -*) OPTIONS="$OPTIONS $ARG";;
  1680. X    *) FILES="$FILES $ARG";;
  1681. X  esac
  1682. Xdone
  1683. Xif test -z "$FILES"
  1684. Xthen
  1685. X  FILES=.
  1686. Xfi
  1687. Xset $FILES
  1688. Xfind $@ -type f -links 1 \( -name '*.MW' -o -name '.*.MW' \) -exec filterfile -dpt {} unsqueeze $OPTIONS \;
  1689. X# stupid find, thinks * doesn't match dot files
  1690. Xexit 0
  1691. END_OF_FILE
  1692. if test 381 -ne `wc -c <'unsqzdir'`; then
  1693.     echo shar: \"'unsqzdir'\" unpacked with wrong size!
  1694. fi
  1695. chmod +x 'unsqzdir'
  1696. # end of 'unsqzdir'
  1697. fi
  1698. if test -f 'mwcat' -a "${1}" != "-c" ; then 
  1699.   echo shar: Will not clobber existing file \"'mwcat'\"
  1700. else
  1701. echo shar: Extracting \"'mwcat'\" \(361 characters\)
  1702. sed "s/^X//" >'mwcat' <<'END_OF_FILE'
  1703. X#!/bin/sh
  1704. XOPTIONS=
  1705. XFILES=
  1706. Xfor ARG
  1707. Xdo
  1708. X  case "$ARG" in
  1709. X    -*) OPTIONS="$OPTIONS $ARG";;
  1710. X    *) ARG="`expr $ARG : '\(.*\.MW\)' '|' $ARG.MW`"
  1711. X       FILES="$FILES $ARG";;
  1712. X  esac
  1713. Xdone
  1714. Xif test -z "$FILES"
  1715. Xthen
  1716. X  echo 'mwcat: fatal: must specify filenames; use unsqueeze for a filter' 1>&2
  1717. X  exit 1
  1718. Xfi
  1719. Xset $FILES
  1720. Xfor ARG
  1721. Xdo
  1722. X  unsqueeze $OPTIONS < "$ARG"
  1723. Xdone
  1724. Xexit 0
  1725. END_OF_FILE
  1726. if test 361 -ne `wc -c <'mwcat'`; then
  1727.     echo shar: \"'mwcat'\" unpacked with wrong size!
  1728. fi
  1729. chmod +x 'mwcat'
  1730. # end of 'mwcat'
  1731. fi
  1732. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  1733.   echo shar: Will not clobber existing file \"'Makefile'\"
  1734. else
  1735. echo shar: Extracting \"'Makefile'\" \(619 characters\)
  1736. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  1737. XCCOPTS=-O
  1738. XNROFFOPTS=-man
  1739. X
  1740. Xdefault: all
  1741. X
  1742. Xall: squeeze unsqueeze squeeze.1 unsqueeze.1 sqz.1 sqzdir.1 mwcat.1
  1743. X
  1744. Xsqueeze: squeeze.c Makefile
  1745. X    cc $(CCOPTS) -o squeeze squeeze.c
  1746. X
  1747. Xunsqueeze: unsqueeze.c Makefile
  1748. X    cc $(CCOPTS) -o unsqueeze unsqueeze.c
  1749. X
  1750. Xsqueeze.1: squeeze.man Makefile
  1751. X    nroff $(NROFFOPTS) < squeeze.man > squeeze.1
  1752. X
  1753. Xunsqueeze.1: unsqueeze.man Makefile
  1754. X    nroff $(NROFFOPTS) < unsqueeze.man > unsqueeze.1
  1755. X
  1756. Xsqz.1: sqz.man Makefile
  1757. X    nroff $(NROFFOPTS) < sqz.man > sqz.1
  1758. X
  1759. Xsqzdir.1: sqzdir.man Makefile
  1760. X    nroff $(NROFFOPTS) < sqzdir.man > sqzdir.1
  1761. X
  1762. Xmwcat.1: mwcat.man Makefile
  1763. X    nroff $(NROFFOPTS) < mwcat.man > mwcat.1
  1764. END_OF_FILE
  1765. if test 619 -ne `wc -c <'Makefile'`; then
  1766.     echo shar: \"'Makefile'\" unpacked with wrong size!
  1767. fi
  1768. # end of 'Makefile'
  1769. fi
  1770. echo shar: End of shell archive.
  1771. exit 0
  1772.  
  1773.